import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_sensor_backend/assets/color.dart';
import 'package:flutter_sensor_backend/assets/storage.dart';
import 'package:flutter_sensor_backend/component/myleading.dart';
import 'package:flutter_sensor_backend/component/niw.dart';

class UseApi extends StatefulWidget {
  const UseApi({super.key});

  @override
  State<UseApi> createState() => _UseApiState();
}

class _UseApiState extends State<UseApi> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: MyLeading(),
        title: Text(
          "使用API接口",
          style: TextStyle(
            color: os_black,
            fontSize: 16,
            fontWeight: FontWeight.normal,
          ),
        ),
      ),
      body: ListView(
        children: [
          Container(
            margin: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
            padding: EdgeInsets.symmetric(horizontal: 20, vertical: 15),
            decoration: BoxDecoration(
              color: os_white,
              borderRadius: BorderRadius.circular(15),
            ),
            child: Column(
              children: [
                Container(height: 5),
                Text(
                  "请使用POST方法",
                  style: TextStyle(
                    color: os_black,
                    fontSize: 16,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                Container(height: 15),
                Container(
                  padding: EdgeInsets.symmetric(horizontal: 20, vertical: 20),
                  decoration: BoxDecoration(
                    color: Color(0xfff6f6f6),
                    borderRadius: BorderRadius.circular(20),
                  ),
                  child: Column(
                    children: [
                      Text(
                        "http://124.223.62.14:8080/addCollection",
                        textAlign: TextAlign.center,
                        style: TextStyle(
                          color: os_black,
                          fontSize: 16,
                          fontWeight: FontWeight.w600,
                        ),
                      ),
                      Container(height: 15),
                      myInkWell(
                        tap: () {
                          Clipboard.setData(
                            ClipboardData(
                              text: "http://124.223.62.14:8080/addCollection",
                            ),
                          );
                        },
                        color: os_color,
                        widget: Container(
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(100),
                          ),
                          padding: EdgeInsets.symmetric(
                            horizontal: 20,
                            vertical: 5,
                          ),
                          child: Text(
                            "复制",
                            style: TextStyle(
                              color: os_white,
                              fontSize: 14,
                              fontWeight: FontWeight.normal,
                            ),
                          ),
                        ),
                        radius: 100,
                      ),
                    ],
                  ),
                ),
                Container(height: 20),
                Text(
                  "请在header中传入Token",
                  style: TextStyle(
                    color: os_black,
                    fontSize: 16,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                Container(height: 15),
                Container(
                  padding: EdgeInsets.symmetric(horizontal: 20, vertical: 20),
                  decoration: BoxDecoration(
                    color: Color(0xfff6f6f6),
                    borderRadius: BorderRadius.circular(20),
                  ),
                  child: Column(
                    children: [
                      Text(
                        "token: {{token}}",
                        textAlign: TextAlign.center,
                        style: TextStyle(
                          color: os_black,
                          fontSize: 16,
                          fontWeight: FontWeight.w600,
                        ),
                      ),
                      Container(height: 15),
                      myInkWell(
                        tap: () async {
                          Clipboard.setData(
                            ClipboardData(
                              text: await getStorage(key: "token"),
                            ),
                          );
                        },
                        color: os_color,
                        widget: Container(
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(100),
                          ),
                          padding: EdgeInsets.symmetric(
                            horizontal: 20,
                            vertical: 5,
                          ),
                          child: Text(
                            "复制Token",
                            style: TextStyle(
                              color: os_white,
                              fontSize: 14,
                              fontWeight: FontWeight.normal,
                            ),
                          ),
                        ),
                        radius: 100,
                      ),
                    ],
                  ),
                ),
                Container(height: 20),
                Text(
                  "请传入form-data",
                  style: TextStyle(
                    color: os_black,
                    fontSize: 16,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                Container(height: 15),
                Container(
                  padding: EdgeInsets.symmetric(horizontal: 20, vertical: 20),
                  decoration: BoxDecoration(
                    color: Color(0xfff6f6f6),
                    borderRadius: BorderRadius.circular(20),
                  ),
                  child: Column(
                    children: [
                      Text(
                        '''{
	  "fallDown": "false",
	  "timestamp":    "1675579682840",
	  "seqDataX": "[]",
	  "seqDataY": "[]",
	  "seqDataZ": "[]",
	  "deviceInfo": "Redmi"
}''',
                        textAlign: TextAlign.start,
                        style: TextStyle(
                          color: os_black,
                          fontSize: 16,
                          fontWeight: FontWeight.w600,
                        ),
                      ),
                      Container(height: 15),
                      myInkWell(
                        color: os_color,
                        tap: () async {
                          Clipboard.setData(
                            ClipboardData(
                              text:
                                  '''{"fallDown":"false", "timestamp":"1675579682840", "seqDataX":"[]", "seqDataY": "[]", "seqDataZ": "[]", "deviceInfo": "Redmi" }''',
                            ),
                          );
                        },
                        widget: Container(
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(100),
                          ),
                          padding: EdgeInsets.symmetric(
                            horizontal: 20,
                            vertical: 5,
                          ),
                          child: Text(
                            "复制",
                            style: TextStyle(
                              color: os_white,
                              fontSize: 14,
                              fontWeight: FontWeight.normal,
                            ),
                          ),
                        ),
                        radius: 100,
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
